//
//  HomeGoodsCell.swift
//  LeGou
//
//  Created by lxm on 2022/7/27.
//

import UIKit

class HomeGoodsCell: UICollectionViewCell {
    @IBOutlet weak var label: UILabel!
    
    @IBOutlet weak var price: UILabel!
    
    @IBOutlet weak var subPrice: UILabel!
    
    @IBOutlet weak var img: UIImageView!
    
    @IBOutlet weak var coupon: UILabel!
    
    @IBOutlet weak var refund: UILabel!
    
    
    static var bootomH : CGFloat = 66.5
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    func pddUI(_ data: PDDModel) {
        label.attributedText = getAtrStr(titleStr: data.goodsName, img: "home_pdd")
        img.zm.setImage(urlStr: data.goodsImageUrl)
        coupon.text = data.couponPrice.zm.toString(keep: 2) + "元"
        refund.text = data.refundMoney(data.userShareCommission) + "元"
        price.attributedText = "".zm.append(str: "¥", attri: ["f" : "12b", "c" : "#DC1826"])
            .zm.append(str: "\(data.currentPrice.zm.toString(keep: 2))", attri: ["f" : "18b", "c" : "#DC1826"])
            .zm.append(str: "券后", attri: ["f" : "12m", "c" : "#DC1826"])
        subPrice.zm.setStrikethroughTitle(title: "¥\(data.oldPrice.zm.toString(keep: 2))")
    }
    
    func getAtrStr(titleStr : String, img: String) -> NSMutableAttributedString {
        let att = NSTextAttachment.init(data: nil, ofType: nil)
        att.image = UIImage.init(named: img)
        att.bounds = CGRect(x: 0, y: -4, width: 20, height: 20)
        let imageStr = NSMutableAttributedString(attachment: att)
        imageStr.append(NSMutableAttributedString.init(string: titleStr))
        return imageStr
    }

}
